package threading;

class thread implements Runnable {
    @Override
    public void run() {
        System.out.println("着是Runnable里面的一个线程");
    }
}
class myThread extends Thread {
    @Override
    public void run() {
        int i = 1;
        while (true) {
            System.out.println("这是myThread内的第"+i+"一个线程!");
            i++;
            if (i == 7){
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class ThreadDemo {
    public static void main(String[] args) {

    }
        public static void main6(String[] args) {
            myThread thread = new myThread();
            thread.start();//调用start方法
        }

    public static void main5(String[] args) {
        Thread thread = new Thread( () -> {
            System.out.println("这是lambda表达式下的一个线程");
        } );
        thread.start();
    }
    public static void main4(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("这是Runnable接口下的一个线程");
            }
        };
        runnable.run();
    }
    public static void main3(String[] args) {
        Thread thread = new Thread(){
            @Override
            public void run() {
                System.out.println("这是Thread类里的一个进程");
            }
        };
        thread.start();
    }
    public static void main2(String[] args) {
        Thread thread = new Thread( () -> {
            int i = 1;
            while(true) {
                System.out.println("这是第"+i+"个线程");
                i++;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (i == 7){
                    break;
                }
            }
        });
        thread.start();
    }
}
